/**
 * @file 权限控制工具类
 * @version 1.0.0
 * @author qingxue
 * @createDate 2024-04-06 20:00
 * @updateDate 2024-04-06 20:00
 */

const { ErrorMessage } = require('@/utils/response/error_message');

/**
 * 权限判定
 * @param permission 接口权限等级
 * @param req 请求对象
 */
module.exports = function (permission, req) {
  const level = req['customData'].level; // 用户权限等级
  if (typeof permission !== 'number' && typeof level !== 'number' || level < permission) {
    throw {
      message: ErrorMessage.PermissionNotAllowedError,
      data: null
    };
  }
};
